import {Injectable, Logger} from "@nestjs/common";
import {MailerService} from "@nestjs-modules/mailer";

@Injectable()
export class MailService {

    private readonly logger = new Logger(MailService.name);

    constructor(
        private readonly mailService: MailerService
    ) {
    }

    /**
     * @Description: 发送验证码
     * @author zhaojiuyi
     * @date 2023/4/12
     * @param {string} mail 发送邮箱
     * @param {string | number} code 验证码
     */
    async sendCode(mail: string, code: string | number) {
        this.logger.log(`发送验证码 ${code} 到 ${mail}`)
        await this.mailService.sendMail({
            to: mail,
            subject: "验证码",
            html: `
                <div style="display: flex;flex-direction: column;align-items: center;">
                    <h3 style="font-weight: bold">【基于知识图谱的书籍推荐系统】</h3>
                    <h4 >你的验证码</h4>
                    <h4><span style="margin: 0 20px;color: rgba(47,47,47,0.83)">${code}</span></h4>
                    <h4>打死不要告诉别人</h4>
                </div>
            `,
        });
    }

}
